package com.wc.算法提高课.A第一章_动态规划.背包模型.潜水员;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/9 20:18
 * @description https://www.acwing.com/problem/content/1022/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 22, M = 80, INF = 0x3f3f3f3f;
    static int[][] f = new int[N][M];
    static int n, m, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= m; j++) {
                f[i][j] = INF;
            }
        }
        f[0][0] = 0;
        while (k-- > 0) {
            int w1 = sc.nextInt(), w2 = sc.nextInt(), v = sc.nextInt();
            for (int i = n; i >= 0; i--) {
                for (int j = m; j >= 0; j--) {
                    // 超过了就按照n,m处理就好了
//                    if(f[i][j] != INF){
//                        if(i + w1 >= n && j + w2 >= m){
//                            if(f[n][m] == -1) f[n][m] = f[i][j] + v;
//                            else f[n][m] = Math.min(f[n][m], f[i][j] + v);
//                        } else if(i + w1 >= n){
//                            if(f[n][j + w2] == -1) f[n][j + w2] = f[i][j] + v;
//                            else f[n][j + w2] = Math.min(f[n][j + w2], f[i][j] + v);
//                        } else if(j + w2 >= m){
//                            if(f[i + w1][m] == -1) f[i + w1][m] = f[i][j] + v;
//                            else f[i + w1][m] = Math.min(f[i + w1][m], f[i][j] + v);
//                        } else {
//                            if(f[i + w1][j + w2] == -1) f[i + w1][j + w2] = f[i][j] + v;
//                            else f[i + w1][j + w2] = Math.min(f[i + w1][j + w2], f[i][j] + v);
//                        }
//                    }
                    f[i][j] = Math.min(f[i][j], f[Math.max(0, i - w1)][Math.max(0, j - w2)] + v);
                }
            }
        }

        out.println(f[n][m]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}